<?php
class Photo extends Controller {

	function __construct()
	{
		parent::Controller();

		$this->load->helper('url');
		$this->load->library(array('imagelib', 'frontview'));
		$this->load->model(array('PhotoModel', 'CategoryModel'));

		$this->smartylib->assign('UserData', $this->session->userdata);
		if(!$this->session->userdata('logged_in')) redirect('/admin/login/');
		
		//$this->smartylib->debugging = true;
	}

	function view($id)
	{
		$this->smartylib->assign('page', $this->frontview->view('admin/'));
		$this->smartylib->assign('photo', $this->PhotoModel->getPhoto($id, true));
		$this->smartylib->assign('category', $this->CategoryModel->getTree());
		$this->smartylib->display('admin/layout.tpl');
	}

	function add($id)
	{
		$this->smartylib->assign('page', $this->frontview->view('admin/'));
		$this->smartylib->assign('category', $this->CategoryModel->getTree());
		$this->smartylib->assign('cat', $this->CategoryModel->getCategory($id, true));
		$this->smartylib->display('admin/layout.tpl');
	}

	function addarchive($id)
	{
		$this->smartylib->assign('cat', $this->CategoryModel->getCategory($id, true));
		$this->smartylib->assign('page', $this->frontview->view('admin/'));
		$this->smartylib->display('admin/layout.tpl');
	}

	function goaddarchive()
	{
		$this->imagelib->uploadArchive(true, true, 150, 400, '');
		redirect('/admin/category/view/'.$this->input->post('category',true).'/');
	}

	function go()
	{
		$this->PhotoModel->action($this->input->post('type',true), $this->input->post('id',true));
	}
}
?>